//
//  DKBaseInfoSelectView.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/5.
//

#import "DKBaseInfoSelectView.h"
#import "DKAuthSelectAlertView.h"
@interface DKBaseInfoSelectView()
@property (nonatomic, strong)UILabel * dk_baseInfoHeadLab;
@property (nonatomic, strong)UITextField * dk_baseInfoField;
@property (nonatomic, strong)UIView * dk_baseInfoView;
@end
@implementation DKBaseInfoSelectView
-(instancetype)init{
    if(self == [super init]){
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_baseInfoHeadLab = [[UILabel alloc] init];
    self.dk_baseInfoHeadLab.textColor = DK_Hex(@"#999999");
    self.dk_baseInfoHeadLab.font = DK_FONT_Regular(14);
    [self addSubview:self.dk_baseInfoHeadLab];
    [self.dk_baseInfoHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(20)));
    }];
    self.dk_baseInfoView = [[UIView alloc] init];
    self.dk_baseInfoView.layer.cornerRadius = DK_IsWidthScale(14);
    self.dk_baseInfoView.backgroundColor = DK_Hex(@"#F7F7F8");
    [self addSubview:self.dk_baseInfoView];
    [self.dk_baseInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(self.dk_baseInfoHeadLab.mas_bottom).offset(DK_IsWidthScale(10));
        make.bottom.equalTo(@(-DK_IsWidthScale(10)));
    }];
    
    self.dk_baseInfoField = [[UITextField alloc] init];
    self.dk_baseInfoField.font = DK_FONT_Medium(14);
    self.dk_baseInfoField.backgroundColor = UIColor.clearColor;
    self.dk_baseInfoField.placeholder = @"Please select";
//    self.dk_baseInfoField.delegate = self;
    [self.dk_baseInfoView addSubview:self.dk_baseInfoField];
    [self.dk_baseInfoField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(46)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    UIImageView* dk_baseDownImgView = [[UIImageView alloc] init];
    dk_baseDownImgView.userInteractionEnabled = YES;
    dk_baseDownImgView.image = DK_GetImage(@"dk_AuthDown");
    [self.dk_baseInfoView addSubview:dk_baseDownImgView];
    [dk_baseDownImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dk_baseInfoField);
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.width.equalTo(@(DK_IsWidthScale(16)));
        make.height.equalTo(@(DK_IsWidthScale(10)));
    }];
    UIButton * dk_baseInfoBtn = [[UIButton alloc] init];
    [dk_baseInfoBtn addTarget:self action:@selector(requestGetCommonDictList) forControlEvents:UIControlEventTouchUpInside];
    [self.dk_baseInfoView addSubview:dk_baseInfoBtn];
    [dk_baseInfoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.dk_baseInfoView);
    }];
}
-(void)setAuthBaseStepSelectType:(AuthBaseStepSelectType)authBaseStepSelectType{
    _authBaseStepSelectType = authBaseStepSelectType;
    if(_authBaseStepSelectType == AuthBaseStepSelectTypeEducationLevel){
        self.dk_baseInfoHeadLab.text = @"Education Level";
    }else if (_authBaseStepSelectType == AuthBaseStepSelectTypeResidence){
        self.dk_baseInfoHeadLab.text = @"Type of Residence";

    }else if (_authBaseStepSelectType == AuthBaseStepSelectTypeProfession){
        self.dk_baseInfoHeadLab.text = @"Profession";

    }else if (_authBaseStepSelectType == AuthBaseStepSelectTypeMaritalStatus){
        self.dk_baseInfoHeadLab.text = @"Marital status";

    }
}
- (void)startSelectBasseStep{
    self.dk_baseInfoView.layer.borderWidth = 0.5;
    self.dk_baseInfoView.layer.borderColor = DK_Hex(@"#4566FF").CGColor;
}
- (NSString *)getStepStatusSelect{
    return self.dk_baseInfoField.text;
}
- (NSString *)makeValue:(AuthBaseStepSelectType)authBaseStepSelectType{
    if(authBaseStepSelectType == AuthBaseStepSelectTypeEducationLevel){
        return @"EDUCATION_LEVEL";
    }else if(authBaseStepSelectType == AuthBaseStepSelectTypeResidence){
        return @"RESIDENCE_TYPE";
    }else if(authBaseStepSelectType == AuthBaseStepSelectTypeProfession){
        return @"OCCUPATION";
    }else if(authBaseStepSelectType == AuthBaseStepSelectTypeMaritalStatus){
        return @"MARITAL_STATUS";
    }else{
        return @"";
    }
}
- (void)requestGetCommonDictList{
    [self updataUserBrhav];
    WeakSelf(self)
    NSMutableDictionary *commonDic = [[NSMutableDictionary alloc] init];
    [commonDic setValue:[self makeValue:self.authBaseStepSelectType] forKey:@"type"];
    [DKPublicHttp apiGetCommonDictListForAPI:commonDic complete:^(NSArray * _Nonnull commonDictMdls) {
        [DKAuthSelectAlertView dk_ShowAuthSelectAlertView:commonDictMdls complete:^(DKAuthCommonDicModel * _Nonnull authCommonDicMdl) {
            weakSelf.authCommonDicMdl = authCommonDicMdl;
            weakSelf.dk_baseInfoField.text = authCommonDicMdl.remark;
            if(weakSelf.SelectScuessBlock){
                weakSelf.SelectScuessBlock();
            }
        }];
    }];
}
- (void)requestUserBrhavRecord:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyBasic withAction:action complete:^{
            
    } fail:^{
            
    }];
}

- (void)updataUserBrhav{
    if(_authBaseStepSelectType == AuthBaseStepSelectTypeEducationLevel){
        [self requestUserBrhavRecord:DK_ActionEducation_Level_Focus withParmDic:@{}];
    }else if(_authBaseStepSelectType == AuthBaseStepSelectTypeResidence){
        [self requestUserBrhavRecord:DK_ActionResidence_Type_Focus withParmDic:@{}];
    }else if(_authBaseStepSelectType == AuthBaseStepSelectTypeProfession){
        [self requestUserBrhavRecord:DK_ActionOccupation_Focus withParmDic:@{}];
    }else if(_authBaseStepSelectType == AuthBaseStepSelectTypeMaritalStatus){
        [self requestUserBrhavRecord:DK_ActionMarital_Status_Focus withParmDic:@{}];
    }
}
@end
